package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.content.service.ArticleCategoryService;
import com.tarena.lbs.pojo.content.dto.ArticleCategoryDTO;
import com.tarena.lbs.pojo.content.param.ArticleCategoryParam;
import com.tarena.lbs.pojo.content.query.ArticleCategoryQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/content/category")
@Api(tags = "文章分类管理")
public class ArticleCategoryController {

    @Resource
    private ArticleCategoryService articleCategoryService;


    @PostMapping("/insert")
    public Result<Void> insert(ArticleCategoryParam articleCategoryParam) {
        articleCategoryService.insert(articleCategoryParam);
        return Result.success();
    }

    @PostMapping("/delete")
    public Result<Void> delete(Integer id) throws BusinessException {
        articleCategoryService.delete(id);
        return Result.success();
    }


    @GetMapping("/get")
    public Result<ArticleCategoryDTO> get(Integer id) throws BusinessException {
        ArticleCategoryDTO articleCategoryDTO = articleCategoryService.get(id);
        return new Result(articleCategoryDTO);
    }


    @PostMapping("/update")
    public Result<Void> update(ArticleCategoryParam articleCategoryParam) throws BusinessException {
        articleCategoryService.update(articleCategoryParam);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<PageResult<ArticleCategoryDTO>> list(ArticleCategoryQuery articleCategoryQuery) {
        PageResult<ArticleCategoryDTO> list = articleCategoryService.list(articleCategoryQuery);
        return new Result<>(list);
    }
}
